<!--
* description: 新增-门店管理
* author:wangjuan
* createdDate:2020-12-4
-->
<template>
  <section class="editStoreManage">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      width="70%"
      :before-close="handleClose"
      @close="sendCode"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :style-type="$store.state.app.dialogType"
      />

      <div class="filter-container filter-params">
        <el-row ref="vailComponentList" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :is-require="comp.isRequire"
            :is-mul="comp.isMul"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :date-options-type="comp.dateOptionsType"
            @changeCode="getComponentCode"
          />
        </el-row>
      </div>

      <mix-button
        class="app-common-mar"
        :dynamic-buttons="tableButtons"
        :template-type="true"
      />
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from '@/components/mixins/formMixins'

export default {
  components: {
    dialogHeader: () => import('@/components/dialogHeader'),
    mixButton: () => import('@/components/basicComponent/mixButton')
  },
  // 组件混入对象
  mixins: [formMixins],

  data() {
    const viewPageCode = 'storeManage-edit'
    return {
      // 保存API配置对象
      // apiConfig: orgApis.mdmOrgInfoMutationSupplierSave,

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          clickEvent: () => this.save(),
          text: this.$t('sys.button.save') /* 保存*/,
          position: 'right'
        },
        {
          compKey: 'btnKey2',
          type: '',
          size: 'small',
          clickEvent: () => this.sendCode('0'),
          text: this.$t('sys.button.cancel') // 取消
        }
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          : [
            {
              compKey: 'compKey1',
              labelName: '门店类型：',
              codeField: 'storeType',
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '门店编码：',
              codeField: 'storeCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: 'SAP客户编码：',
              codeField: 'SAPClientCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey4',
              labelName: '门店名称：',
              codeField: 'storeName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey5',
              labelName: '所属大区：',
              codeField: 'bigAreaCode',
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey6',
              labelName: '所属小区：',
              codeField: 'smallAreaName',
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              isMust: true
            },
            {
              compKey: 'compKey7',
              labelName: '省份：',
              codeField: 'province',
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey8',
              labelName: '城市：',
              codeField: 'city',
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey9',
              labelName: '区县：',
              codeField: 'country',
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              isMust: true
            },
            {
              compKey: 'compKey10',
              labelName: '门店全称：',
              codeField: 'storeFullName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey11',
              labelName: '经营状态：',
              codeField: 'manageStatus',
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              isMust: true
            },
            {
              compKey: 'compKey12',
              labelName: '上线时间：',
              codeField: 'onlineTime',
              component: () => import('@/components/org/datePicker/datePicker'),
              type: 'datePicker',
              isMust: true
            },
            {
              compKey: 'compKey13',
              labelName: '建店地址：',
              codeField: 'buildStoreAddress',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey14',
              labelName: '注册资金（万元）：',
              codeField: 'registeredFund',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey15',
              labelName: '停业时间：',
              codeField: 'closingTime',
              component: () => import('@/components/org/datePicker/datePicker'),
              type: 'datePicker',
              isMust: true
            },
            {
              compKey: 'compKey16',
              labelName: '门店级别：',
              codeField: 'storeLevel',
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              isMust: true
            },
            {
              compKey: 'compKey17',
              labelName: '组织机构代码：',
              codeField: 'organizingInstitutionCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey18',
              labelName: 'POSID：',
              codeField: 'POSID',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            }
          ],

      // 标题
      textMap: {
        edit: '门店信息维护',
        add: '门店信息维护'
      },

      // 表单数据（无需赋值，由混入对象赋值）
      formField: this.$utils.getFormField(this, {
        storeType: '',
        storeCode: '',
        SAPClientCode: '',
        storeName: '',
        bigAreaCode: '',
        smallAreaName: '',
        province: '',
        city: '',
        country: '',
        storeFullName: '',
        manageStatus: '',
        onlineTime: '',
        buildStoreAddress: '',
        registeredFund: '',
        closingTime: '',
        storeLevel: '',
        organizingInstitutionCode: '',
        POSID: ''
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode])
    }
  },

  created() {

  },

  methods: {
    // 关闭弹窗
    handleClose(done) {
      this.$confirm('还未保存，确认关闭窗口？')
        .then(_ => {
          this.orderList = []
          this.$emit('update:popupsVisible', false)
          done()
        })
        .catch(_ => {})
    },
    // 保存
    save() {
      const that = this
      this.$utils.validataMoth(that, 'validpopup')
      if (this.valid) {
        // 保存表单
        this.saveForm()
      }
    }
  }
}
</script>

<style scoped>
.promptSpan{
  position: absolute;
  bottom: 26px;
  right: 335px;
  color: #e70020;
}
</style>
